<?php namespace app\home\controller;

class Entry extends Marster{
	public function index() {
//		文章内容区域取得文章名和文章内容
		$article=Db::table('article')
			->join('article_data','article_data.article_aid','=','article.aid')
			->limit(4)
			->get(['article.aid','article.ctitle','article_data.content','thumb','sendtime']);
//		p($article);
		View::with('article',$article);
		//field获取制定的字段值文章表和分类表关联
		$articleData=Db::table('article')->join('category','category_cid','=','cid')->field('aid,ctitle,sendtime,author,cname,cdes,digest,ckeywords,thumb')->first();
//		p($articleData);die;
		View::with('articleData',$articleData);

//		文章表和标签表关联
		$tagData=Db::table('article')->join('category','category_cid','=','cid')->get();
//		p($tagData);die;
		foreach($tagData as $k=>$v){
			$tagData[$k]['tag']=Db::table('tag')->join('article_tag','tag_tid','=','tid')->where('article_aid',$v['aid'])->get(['tname,tid']);
	}
//		标签
		$tag=Db::table('article')->join('category','category_cid','=','cid')->limit(1,3)->get();
//			p($tag);die;
		View::with('tag',$tag);
//		p($tagData);
		View::with('tagData',$tagData);
//		p($tagData);
//		根据点击次数找文章
		$click=Db::table('article')
			->join('category','category_cid','=','cid')
			->orderBy('click','DESC')
			->get(['cid','cname','ctitle','aid']);
//		p($click);die;
		View::with('click',$click);

		return view();
	}

}